package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;

/**
 * 图片控制器..
 */
@RestController
@RequestMapping("/images")
public class ImageController {
    /**
     * 图片上传
     * @param upload
     * @return
     */
    @PostMapping
    public Object headImgUpload(MultipartFile upload){
        HashMap<String, Object> map = new HashMap<>();
        try {
            String url = UploadUtil.upload(upload, UploadUtil.BASE_PATH);
            map.put("url",url);
            map.put("uploaded",1);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("uploaded",0);
            HashMap<String, String> temp = new HashMap<>();
            temp.put("message","上传失败!");
            map.put("error","temp");
        }
        return map;
    }

    /** tiger
     * 获取图片方法
     */
    public void getMap(){
        System.out.println("图片更新 ");
    }


    /**
     * tuan
     * xxx
     */
   public void setImg(){
       System.out.println(1);
   }

}
